﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
	using ufida.u9.ait.openapi.utils;
	using UFIDA.U9.CBO.Pub.Controller;
	using UFIDA.U9.InvDoc.CheckDiffBill;
	using UFIDA.U9.ISV.CheckDiffSV;
	using UFIDA.U9.ISV.CheckDiffSV.Proxy;
	using UFSoft.UBF.AopFrame;
	using UFSoft.UBF.Business;
	using UFSoft.UBF.Transactions;
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// CheckDiffSaveSV partial 
	/// </summary>	
	public partial class CheckDiffSaveSV
	{
		internal BaseStrategy Select()
		{
			return new CheckDiffSaveSVImpementStrategy();
		}
	}

	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class CheckDiffSaveSVImpementStrategy : BaseStrategy
	{
		public CheckDiffSaveSVImpementStrategy() { }

		public override object Do(object obj)
		{
			CheckDiffSaveSV bpObj = (CheckDiffSaveSV)obj;

            //try
            //{
            //	if (bpObj.Data == null || bpObj.Data.Count == 0)
            //		throw new Exception("传入参数为空");
            //	List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

            //	List<object> inputdtos = DTOUtils.DTOListPropCopy(bpObj.Data.ConvertAll(item => item as object)
            //		, typeof(CheckDiffData));
            //	foreach (CheckDiffData dto in inputdtos)
            //	{
            //		CheckDiffBill item = CheckDiffBill.Finder.Find($"DocNo='{dto.DocNo}'");
            //		if (item == null)
            //		{
            //			//新增逻辑
            //			CreateCheckDiffSVProxy proxy = new CreateCheckDiffSVProxy();
            //			proxy.CheckDiffList = new List<CheckDiffData> { dto };
            //			List<CommonArchiveDataDTOData> ret = proxy.Do();

            //			//修改单号
            //			CheckDiffBill doc = CheckDiffBill.Finder.FindByID(ret[0].ID);
            //			if (doc == null)
            //				throw new Exception("修改单号,查找单据失败!");
            //			using (ISession se = Session.Open())
            //			{
            //				doc.DocNo = dto.DocNo;
            //				se.Commit();
            //			}

            //			//处理返回
            //			if (ret.Count > 0)
            //			{
            //				ret[0].Code = doc.DocNo;
            //				retlist.Add(ret[0]);
            //			}

            //			//自动审核,因为要取价,暂不自动审核

            //		}
            //		else
            //		{
            //			//修改逻辑
            //			throw new AITException(599, $"单号:{dto.DocNo}已经存在,不能生成!");
            //		}
            //	}

            //	return ResultUtils.success(bpObj, bpObj.Data, retlist);
            //}
            //catch (Exception ex)
            //{
            //	return ResultUtils.error(bpObj, bpObj.Data, ex);
            //}

            //因为要取价,不自动审核
            return CodeUtils.DocSaveRT(bpObj, bpObj.Data, CheckDiffBase.CreateDoc, null);

		}
	}

	#endregion


}